<?php
include 'config.php';

try {
    $db = new PDO("odbc:$odbc_name", '', '');

    $db->query("SET NAMES 'utf8'");
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
    error_log($e->getMessage());
    die("A database error was encountered, maybe ODBC name $odbc_name was not set in the OS yet.");
}
?>
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Display</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=0">
        <meta name="description" content="Demo of Scrolld.js">
        <meta name="author" content="">

        <!--link rel="stylesheet/less" href="less/bootstrap.less" type="text/css" /-->
        <!--link rel="stylesheet/less" href="less/responsive.less" type="text/css" /-->
        <!--script src="js/less-1.3.3.min.js"></script-->
        <!--append ‘#!watch’ to the browser URL, then refresh the page. -->

        <link href="css/bootstrap.min.css" rel="stylesheet">
        <link href="css/style.css" rel="stylesheet">
        <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
        <!--[if lt IE 9]>
          <script src="js/html5shiv.js"></script>
        <![endif]-->

        <!-- Fav and touch icons -->
        <link rel="apple-touch-icon-precomposed" sizes="144x144" href="img/apple-touch-icon-144-precomposed.png">
        <link rel="apple-touch-icon-precomposed" sizes="114x114" href="img/apple-touch-icon-114-precomposed.png">
        <link rel="apple-touch-icon-precomposed" sizes="72x72" href="img/apple-touch-icon-72-precomposed.png">
        <link rel="apple-touch-icon-precomposed" href="img/apple-touch-icon-57-precomposed.png">
        <link rel="shortcut icon" href="img/favicon.png">
        <link rel="shortcut icon" href="img/favicon.ico"/>
        <!-- link href="css/combinedCSS.css" rel="stylesheet" -->

        <script type="text/javascript" src="js/jquery.min.js"></script>
        <script type="text/javascript" src="js/bootstrap.min.js"></script>
        <script type="text/javascript" src="js/scripts.js"></script>
        <!-- CSS -->
        <style type="text/css">

            * {
                box-sizing: border-box;
                -moz-box-sizing: border-box;
            }

            html, body {
                margin: 0;
                padding: 0;
                height: 100%;
            }

            #fixedNavBar > ul{
                list-style: none;
                text-decoration: none;
            }

            #fixedNavBar{
                position: fixed;
                width: 100%;
                padding: 0.5% 0;
                top: 0;
                z-index: 8888;
                background: #4B5763 !important;
            }
        </style>
        <script>
            setTimeout(function() {
                window.location.reload(1);
            }, 3000);</script>
    </head>

    <body>
        <div class="container">
            <div class="row clearfix">
                <div class="col-md-12 column">
                    <img src="images/logo.png" name="logo" id="logo" href="images/the mint3.jpg" />
                </div>
                <div class="col-md-12 column">
                    <table class="table table-condensed">
                        <thead>
                            <tr>
                                <th class="col-md-8">Name</th>
                                <th class="col-md-1">Last Price</th>
                                <th class="col-md-1">Current Price</th>
                                <th class="col-md-1">Change</th>
                                <th class="col-md-1">Qty Last</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $recperpage = isset($_GET['lines']) ? $_GET['lines'] : null;
                            $pageno = isset($_GET['page']) ? $_GET['page'] : null;
                            $startrecno = $recperpage * ($pageno - 1);
                            $endrecno = $startrecno + $recperpage;
                            try {
                                if (isset($recperpage) and isset($pageno)) {
                                    $query = "select * from productsettings where selected = .t. and (recno() >= $startrecno and recno() < $endrecno) order by name";
                                } else {
                                    $query = "select * from productsettings where selected = .t. order by name";
                                }
                                $query = "select * from productsettings where selected = .t. order by name";
                                $stmt = $db->prepare("$query");
                                $stmt->execute();

                                while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
                                    ?>
                                    <tr>
                                        <td><?php echo $row['name']; ?></td>
                                        <td><?php echo sprintf('%-5.2f', $row['lastprice']); ?></td>
                                        <td><?php echo sprintf('%-5.2f', $row['currprice']); ?></td>
                                        <td><?php
                            if ($row['change'] < 0) {
                                echo '<font class="red">';
                            } else if ($row['change'] > 0) {
                                echo '<font class="green">';
                            }
                            echo sprintf('%+5.2f', $row['change']);
                            if ($row['change'] <> 0) {
                                echo '</font>';
                            }
                                    ?>
                                        </td>
                                        <td><?php echo $row['round_qty'] - $row['roundcount']; ?></td>
                                    </tr>
                                    <?php
                                }
                            } catch (PDOException $e) {
                                print $e->getMessage();
                            }
                            unset($db);
                            unset($stmt);
                            ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
        <script src="js/scrolld.min.js"></script>
        <script type="text/javascript">$("[id*='Btn']").stop(true).on('click', function(e) {
                e.preventDefault();
                $(this).scrolld();
            })</script>
        <script src="js/deferDemo.js"></script>
    </body>
</html>
